//---------------------------------------------------------------------------- // File: C3DTypes.cpp // Class: C3DTypes // Type: Common 3D Types // Author: Ken Anderson // Date: 11/7/04 // Desc: Extended from the Common Types header file to expand on simple classes // such as the vector class. // Required headers: // 1. C3DTypes.h == Header that has the following class definitions for the vectors. //---------------------------------------------------------------------------- #include "C3DTypes.h" /////////////////////////////////////////////////////////////////////////////////////////////////////// // Class: C3DVector2 // Name: Operation FUNCTIONALITY // Permission: Public // Date: 11/8/04 // Type: 2 Point Vector. // Desc: Provides operator, casting and construction functionality for the class. ////////////////////////////////////////////////////////////////////////////////////////////////////// C3DVector2::C3DVector2(const float* pf) { x = pf[0]; y = pf[1]; } C3DVector2::C3DVector2(float fx, float fy) { x = fx; y = fy; } C3DVector2::operator float* () { return (float *) &x; } C3DVector2::operator const float* () const { return (const float *) &x; } C3DVector2& C3DVector2::operator += ( const C3DVector2& v ) { x += v.x; y += v.y; return *this; } C3DVector2& C3DVector2::operator -= ( const C3DVector2& v ) { x -= v.x; y -= v.y; return *this; } C3DVector2& C3DVector2::operator *= ( float f ) { x *= f; y *= f; return *this; } C3DVector2& C3DVector2::operator /= ( float f ) { float fInv = 1.0f / f; x *= fInv; y *= fInv; return *this; } C3DVector2 C3DVector2::operator + () const { return *this; } C3DVector2 C3DVector2::operator - () const { return C3DVector2(-x, -y); } C3DVector2 C3DVector2::operator + ( const C3DVector2& v ) const { return C3DVector2(x + v.x, y + v.y); } C3DVector2 C3DVector2::operator - ( const C3DVector2& v ) const { return C3DVector2(x - v.x, y - v.y); } C3DVector2 C3DVector2::operator * ( float f ) const { return C3DVector2(x * f, y * f); } C3DVector2 C3DVector2::operator / ( float f ) const { float fInv = 1.0f / f; return C3DVector2(x * fInv, y * fInv); } C3DVector2 operator * ( float f, const C3DVector2& v ) { return C3DVector2(f * v.x, f * v.y); } bool C3DVector2::operator == ( const C3DVector2& v ) const { return x == v.x && y == v.y; } bool C3DVector2::operator != ( const C3DVector2& v ) const { return x != v.x || y != v.y; } /////////////////////////////////////////////////////////////////////////////////////////////////////// // Class: C3DVector3 // Name: Operation FUNCTIONALITY // Permission: Public // Date: 11/8/04 // Type: 3 Point Vector. // Desc: Provides operator, casting and construction functionality for the class. ////////////////////////////////////////////////////////////////////////////////////////////////////// C3DVector3::C3DVector3(const float* pf) { x = pf[0]; y = pf[1]; z = pf[2]; } C3DVector3::C3DVector3(float fx, float fy, float fz) { x = fx; y = fy; z = fz; } C3DVector3::operator float* () { return (float *) &x; } C3DVector3::operator const float* () const { return (const float *) &x; } C3DVector3& C3DVector3::operator += ( const C3DVector3& v ) { x += v.x; y += v.y; z += v.z; return *this; } C3DVector3& C3DVector3::operator -= ( const C3DVector3& v ) { x -= v.x; y -= v.y; z -= v.z; return *this; } C3DVector3& C3DVector3::operator *= ( float f ) { x *= f; y *= f; z *= f; return *this; } C3DVector3& C3DVector3::operator /= ( float f ) { float fInv = 1.0f / f; x *= fInv; y *= fInv; z *= fInv; return *this; } C3DVector3 C3DVector3::operator + () const { return *this; } C3DVector3 C3DVector3::operator - () const { return C3DVector3(-x, -y, -z); } C3DVector3 C3DVector3::operator + ( const C3DVector3& v ) const { return C3DVector3(x + v.x, y + v.y, z + v.z); } C3DVector3 C3DVector3::operator - ( const C3DVector3& v ) const { return C3DVector3(x - v.x, y - v.y, z + v.z); } C3DVector3 C3DVector3::operator * ( float f ) const { return C3DVector3(x * f, y * f, z * f); } C3DVector3 C3DVector3::operator / ( float f ) const { float fInv = 1.0f / f; return C3DVector3(x * fInv, y * fInv, z * fInv); } C3DVector3 operator * ( float f, const C3DVector3& v ) { return C3DVector3(f * v.x, f * v.y, f * v.z); } bool C3DVector3::operator == ( const C3DVector3& v ) const { return x == v.x && y == v.y && z == v.z; } bool C3DVector3::operator != ( const C3DVector3& v ) const { return x != v.x || y != v.y || z != v.z; } /////////////////////////////////////////////////////////////////////////////////////////////////////// // Class: C3DVector4 // Name: Operation FUNCTIONALITY // Permission: Public // Date: 11/8/04 // Type: 4 Point Vector. // Desc: Provides operator, casting and construction functionality for the class. ////////////////////////////////////////////////////////////////////////////////////////////////////// C3DVector4::C3DVector4(const float* pf) { x = pf[0]; y = pf[1]; z = pf[2]; w = pf[3]; } C3DVector4::C3DVector4(float fx, float fy, float fz, float fw) { x = fx; y = fy; z = fz; w = fw; } C3DVector4::operator float* () { return (float *) &x; } C3DVector4::operator const float* () const { return (const float *) &x; } C3DVector4& C3DVector4::operator += ( const C3DVector4& v ) { x += v.x; y += v.y; z += v.z; w += v.w; return *this; } C3DVector4& C3DVector4::operator -= ( const C3DVector4& v ) { x -= v.x; y -= v.y; z -= v.z; w -= v.w; return *this; } C3DVector4& C3DVector4::operator *= ( float f ) { x *= f; y *= f; z *= f; w *= f; return *this; } C3DVector4& C3DVector4::operator /= ( float f ) { float fInv = 1.0f / f; x *= fInv; y *= fInv; z *= fInv; w *= fInv; return *this; } C3DVector4 C3DVector4::operator + () const { return *this; } C3DVector4 C3DVector4::operator - () const { return C3DVector4(-x, -y, -z, -w); } C3DVector4 C3DVector4::operator + ( const C3DVector4& v ) const { return C3DVector4(x + v.x, y + v.y, z + v.z, w + v.w); } C3DVector4 C3DVector4::operator - ( const C3DVector4& v ) const { return C3DVector4(x - v.x, y - v.y, z + v.z, w + v.w); } C3DVector4 C3DVector4::operator * ( float f ) const { return C3DVector4(x * f, y * f, z * f, w * f); } C3DVector4 C3DVector4::operator / ( float f ) const { float fInv = 1.0f / f; return C3DVector4(x * fInv, y * fInv, z * fInv, w * fInv); } C3DVector4 operator * ( float f, const C3DVector4& v ) { return C3DVector4(f * v.x, f * v.y, f * v.z, f * v.w); } bool C3DVector4::operator == ( const C3DVector4& v ) const { return x == v.x && y == v.y && z == v.z && w == v.w; } bool C3DVector4::operator != ( const C3DVector4& v ) const { return x != v.x || y != v.y || z != v.z || w != v.w; }